﻿<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="StrategyMapping.aspx.vb" Inherits="StrategyMapping" %>
 <%@ Register Assembly="ISNet.WebUI.WebTreeView" Namespace="ISNet.WebUI.WebTreeView" TagPrefix="ISWebTreeView" %>

<%@ Register Assembly="ISNet.WebUI.WebGrid" Namespace="ISNet.WebUI.WebGrid" TagPrefix="ISWebGrid" %>

<%@ Register Assembly="ISNet.WebUI.WebCombo" Namespace="ISNet.WebUI.WebCombo" TagPrefix="ISWebCombo" %>

<%@ Register Assembly="ISNet.WebUI.WebDesktop" Namespace="ISNet.WebUI.WebDesktop" TagPrefix="ISWebDesktop" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
        <link href="js/magicsuggest-1.2.6.css" rel="stylesheet" />
    <script src="js/magicsuggest-1.2.6.js"></script>
    <script src="script/packed.js"></script>
    <script src="script/tinybox.js"></script>
    <link href="script/style.css" rel="stylesheet" />
    <script type="text/javascript" src="js/JSON.js"></script>
    <script type="text/javascript">
        function openJS() { alert('loaded') }
        function closeJS() { doupdate() }
        function closeJS2() { doupdate() }
        function doupdate() {
            var grid = ISGetObject("WebGrid1");
            grid.ClearSelectedObject();
            grid.RootTable.UpdateUI();
            grid.RefreshAll();

        }
        function popupattach1() {

            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();



            //get the key value of selected row.
            var key = row.KeyValue;

            TINY.box.show({ iframe: 'neatupload.aspx?BDID=' + key, boxid: 'frameless', width: 540, height: 450, fixed: false, maskid: 'lightmask', maskopacity: 40, closejs: function () { closeJS() } });




        }
        function popupkrajay3(modes,Id ,py, FundCenter, Cmmts, FundedProgram) {


            TINY.box.show({ iframe: 'Sm01Popup.aspx?mode=' + modes + '&Id=' + Id + '&PlanYear=' + py + '&FundCenter=' + FundCenter + '&Cmmts=' + Cmmts + '&FundedProgram=' + FundedProgram, boxid: 'frameless', width: 820, height: 450, fixed: false, maskid: 'lightmask', maskopacity: 40, closejs: function () { closeJS() } });




        }
        function popupattach2() {

            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();
            var key = row.KeyValue;

            //get the key value of selected row.
            TINY.box.show({ iframe: 'AttachmentListPopup.aspx?BDID=' + key, boxid: 'frameless', width: 350, height: 250, fixed: false, maskid: 'lightmask', maskopacity: 40, closejs: function () { closeJS2() } })
        }


        function CustomRequestGenerate(uniqueID) {

            if (confirm('กรุณายืนยันการดึงข้อมูลเข้าระบบใหม่') == false) {
                return false
            }



            __doPostBack(uniqueID, '');


            return true;
        }

    </script>
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    
    <script>

        function WebGrid1_OnRowValidate(rowObject) {
            // retrieves WebGrid's object
            var grid = ISGetObject("WebGrid1");

            // access WebGrid's RootTable
            var rootTable = grid.RootTable;

            var row = rootTable.ToRowObject(rowObject); // convert the rowObject (HTMLElement) to WebGridRow object
            var htmlRow = row.GetElement();
            var cells = row.GetCells(); // get collection of WebGridCell
            var error = 0;


            //alert("1");
            var err_text = "กรุณาตรวจสอบ \n"

            //alert("1");
            var data
            data = wgGetCellByPosition(htmlRow, 0).innerText;
            if (data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                err_text = err_text + "\n ● Commitment Item ";
                error = error + 1;
            }

            data = wgGetCellByPosition(htmlRow, 1).innerText;
            if (data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                err_text = err_text + "\n ● ปี ";
                error = error + 1;
            }

            data = wgGetCellByPosition(htmlRow, 2).innerText;
            if (data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                err_text = err_text + "\n ● ชื่อ Commitment Item ";
                error = error + 1;
            }

            //alert("2");
            if (error == 0) {

                return true;
            } else {
                alert(err_text);
                return false;
            }

        }

        function WebGrid1_OnEditKeyDown(controlId) {
            //alert(event.keyCode);
            var grid = ISGetObject("WebGrid1");

            var totalRows = grid.TotalRows;
            var totalCells = grid.TotalCells;
            var curRow = grid.GetSelectedObject().rowIndex;
            var curCell = grid.GetActiveEditCell().cellIndex;

            // if enter key
            if (event.keyCode == 13) {
                return false;
                //var ar = grid.getActiveRow();
                //if (ar.IsAddNewRow) {
                //    ar.commit();
                //}
                //else {
                //    event.keyCode = 40;
                //    keyDown(curRow, curRow + 1, curCell - 1);
                //}
            }

                // if up arrow
            else if (event.keyCode == 38) {
                if (totalRows >= 2) {
                    if (curRow > 0) {
                        keyDown(curRow, curRow - 1, curCell - 1);
                    }
                }
            }

                // if down arrow key
            else if (event.keyCode == 40) {
                if (totalRows >= 2) {
                    if (curRow < totalRows - 1) {
                        keyDown(curRow, curRow + 1, curCell - 1);
                    }
                }
            }
                // if left arrow key
            else if (event.keyCode == 37) {
                if (curCell > 0) {
                    //jq(document).trigger(jq.Event('keydown', { keyCode: 9, shiftKey: true }));
                    //var press = jQuery.Event("keydown");
                    //press.shiftKey = false;
                    //press.which = 9;
                    //jq("WebGrid1").trigger(press);
                    //alert("x");
                    //return;
                    keyDown2(curRow, curRow, curCell - 2);
                }
            }
                // if right arrow key
            else if (event.keyCode == 39) {
                //if (curCell < totalCells - 1) {
                event.keyCode = 9;
                //}
            }


        }
        function keyDown(curRow, nextRow, cell) {
            var grid = ISGetObject("WebGrid1");
            var nextRowEl = grid.RootTable.GetRow(nextRow);
            var curRowEl = grid.RootTable.GetRow(curRow);
            var cell1 = nextRowEl.GetCell(cell);
            var cell2 = curRowEl.GetCell(cell);
            grid.SetFocus();
            cell2.Select(true);
            nextRowEl.Select();
            cell1.ActivateEdit();
        }
        function keyDown2(curRow, nextRow, cell) {
            var grid = ISGetObject("WebGrid1");
            var nextRowEl = grid.RootTable.GetRow(nextRow);
            var curRowEl = grid.RootTable.GetRow(curRow);
            var cell1 = nextRowEl.GetCell(cell);
            var cell2 = curRowEl.GetCell(cell);
            grid.SetFocus();
            cell1.Select(true);
            nextRowEl.Select();
            cell1.ActivateEdit();

        }

        function triggerKeyEvents(field, keyCode, shiftKey, ctrlKey) {

            field = $(field);

            shiftKey = Boolean(shiftKey);

            ctrlKey = Boolean(ctrlKey);


            field.simulate("keydown", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });

            field.simulate("keypress", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });


            if (field.is(HTML5_TEXT_INPUT_FIELD_SELECTOR)) {

                applyKeyCodeToValue(field, keyCode);

            }


            field.simulate("keyup", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });

        }

        function SaveScrollPosition(gridId, action) {
            // collecting the last position
            // of the vertical scrollbar
            // by obtaining the scrollTop property
            var grid = ISGetObject(gridId);
            // obtain the scrollTop and scrollLeft property 
            // of the vertical scrollbar and horizontal scrollbar
            var vl = grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollTop + "";
            var hl = grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollLeft + "";
            // only send the scrollTop property
            // of the server if the action performed
            // by the grid OTFPB is 'Refresh'

            //if (action == "Refresh") {
            // sending over the scrollTop and scrollLeft property
            // to the server by using AddInput method
            grid.AddInput("scrollTopPos", vl);
            grid.AddInput("scrollLeftPos", hl);
            //}

            return true;
        }
        function ApplyLatestScroll(gridId, y, x) {
            // set back the previous scrollTop and scrollLeft property or
            // vertical and horizontal scroll position with 
            // the parameter sent from the server side
            var grid = ISGetObject(gridId);
            // manually configure the vertical and horizontal scroll position
            grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollTop = y;
            grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollLeft = x;

            var cellEl = grid.GetActiveEditCell().ToCellObject();
            grid.SetFocus();
            cellEl.ActivateEdit();
            return true;
        }

        function CustomRequestEdit(del) {
        }
        function CustomRequestDel(del) {

            if (confirm('กรุณายืนยันการลบข้อมูล') == false) {
                return false
            }

           
            
            var grid = ISGetObject("WebGrid1");


            grid.AddInput("Id", del);

            grid.SendCustomRequest();



            event.cancelBubble = true;
            event.returnValue = false;
        }


    </script>
    <div style="margin-left: 10px; padding: 10px 10px 10px 10px;">
        <div align="left" style="width: 100%; float: left; margin-top: 10px;">
            <asp:Label ID="ScreenName" runat="server"></asp:Label>
        </div>
        <div style="text-align: right; float: left; width: 98%; margin-top: 10px; -webkit-border-radius: 5px; padding: 5px 5px 0px 0px;">

            <div style="text-align: left; float: left; width: 75%; border: solid; border-color: gray; border-width: 1px; margin-top: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; padding: 5px 5px 5px 5px; height: 52px;">
                <table style="margin-left: 30px; margin-bottom: 1px; margin-top: 1px;">
                    <tr>
                        <td>
                            <asp:Label ID="Label1" runat="server" Text="Fund center Code"></asp:Label></td>

                        <td style="width: 5px">&nbsp;</td>

                        <td>
                             <ISWebCombo:WebCombo ID="FundCenter" Width="200px" runat="server" UseDefaultStyle="True"  
                                 DataTextField="Description" DataValueField="FundCenterCode" Height="20px" 
                                 OnInitializeDataSource="FundCenter_InitializeDataSource" AdditionalSearchFields="FundCenterCode" 
                                 AllowWildCardSearch="true">
                                            <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" ComboMode="MultipleColumns">
                                            </LayoutSettings>
                                            <Columns>
                                                <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ FundCenter" Width="250px" />
                                                <ISWebCombo:WebComboColumn BaseFieldName="FundCenterCode" Name="FundCenterCode" HeaderText="รหัส FundCenter" Width="80px" />
                                            </Columns>
                                        </ISWebCombo:WebCombo>

                        </td>
                        <td>
                            <asp:Label ID="Label3" runat="server" Text="Funded Program"></asp:Label></td>

                        <td style="width: 5px">&nbsp;</td>

                        <td>
                             <ISWebCombo:WebCombo ID="FundedProgram" Width="200px" runat="server" UseDefaultStyle="True"  
                                    DataTextField="Description" DataValueField="FundedProgram" Height="20px"
                                  OnInitializeDataSource="FundedProgramProjects_InitializeDataSource" AdditionalSearchFields="FundedProgram" 
                                 AllowWildCardSearch="true">
                                            <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" ComboMode="MultipleColumns">
                                            </LayoutSettings>
                                            <Columns>
                                                <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ Funded Program" Width="250px" />
                                                <ISWebCombo:WebComboColumn BaseFieldName="FundedProgram" Name="FundedProgram" HeaderText="รหัส Funded Program" Width="80px" />
                                            </Columns>
                                        </ISWebCombo:WebCombo>

                        </td>
                    </tr>
                     <tr>
                        <td>
                            <asp:Label ID="Label4" runat="server" Text="Commitment"></asp:Label></td>

                        <td style="width: 5px">&nbsp;</td>

                        <td>
                             <ISWebCombo:WebCombo ID="Cmmts" Width="200px" runat="server" UseDefaultStyle="True"  
                                 DataTextField="Description" DataValueField="CmmtCode" Height="20px" 
                                 OnInitializeDataSource="Cmmts_InitializeDataSource" AdditionalSearchFields="CmmtCode" 
                                 AllowWildCardSearch="true">
                                            <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" ComboMode="MultipleColumns">
                                            </LayoutSettings>
                                            <Columns>
                                                <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ Commitment" Width="250px" />
                                                <ISWebCombo:WebComboColumn BaseFieldName="CmmtCode" Name="FundCenterCode" HeaderText="รหัส Commitment" Width="80px" />
                                            </Columns>
                                        </ISWebCombo:WebCombo>

                        </td>
                        <td>
                            <asp:Label ID="Label5" runat="server" Text="Strategy"></asp:Label></td>

                        <td style="width: 5px">&nbsp;</td>

                        <td>
                             <ISWebCombo:WebCombo ID="Strategy" Width="200px" runat="server" UseDefaultStyle="True"  
                                 DataTextField="Description" DataValueField="StrategyCode" Height="20px" 
                                 OnInitializeDataSource="Strategy_InitializeDataSource" AdditionalSearchFields="StrategyCode" 
                                 AllowWildCardSearch="true">
                                            <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" ComboMode="MultipleColumns">
                                            </LayoutSettings>
                                            <Columns>
                                                <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ Strategy" Width="250px" />
                                                <ISWebCombo:WebComboColumn BaseFieldName="StrategyCode" Name="FundCenterCode" HeaderText="รหัส Strategy" Width="80px" />
                                            </Columns>
                                        </ISWebCombo:WebCombo>

                        </td>
                    </tr>
                </table>

            </div>
            <div style="text-align: center; float: left; width: 20%; height: 52px; border: solid; border-color: gray; border-width: 1px; margin-top: 5px; margin-left: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; padding: 5px 5px 5px 5px;">
                &nbsp;&nbsp;&nbsp;&nbsp; 
                <asp:Label ID="Label2" runat="server" Text="ปีงบประมาณ"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp; 
                <asp:TextBox ID="PlanYearsTxt" runat="server" Width="40px" Style="text-align: center;" MaxLength="4"></asp:TextBox>

            </div>
        </div>
        <div style="text-align: right; float: left; width: 97%; border: solid; border-color: gray; border-width: 1px; margin-top: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; padding: 5px 5px 5px 5px;">

            <table id="t_countdata" runat="server" width="300" visible="false" border="0" style="float: left; margin-left: 13px;">
                <tr>
                    <td align="left" style="width: 80px;" valign="middle">
                        <asp:Label ID="L_data" runat="server" Text="ผลการค้นหา: "></asp:Label>
                    </td>
                    <td align="left">
                        <asp:Label ID="L_CountData" runat="server" ForeColor="red"></asp:Label>
                        <asp:Label ID="L_test" runat="server" CssClass="label" Visible="false"></asp:Label>
                        &nbsp;
                    </td>
                </tr>
            </table>
            <table style="float: right;">
                <tr>
                    <td>
                        <asp:ImageButton ID="GenerateBtn" runat="server" ImageUrl="Icons/export.jpg" OnClientClick="return CustomRequestGenerate(this.name);" />
                        <asp:ImageButton ID="SearhBtn" runat="server" ImageUrl="Icons/search.jpg" />
                                    &nbsp;<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="Icons/add.png" />
                        
                    </td>
                </tr>
            </table>
        </div>

        <div style="float: left; width: 97%; border: solid; border-color: gray; border-width: 1px; margin-top: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; padding: 5px 5px 5px 5px;">
            <ISWebGrid:WebGrid ID="WebGrid1" runat="server" UseDefaultStyle="True" Width="100%" DefaultStyleMode="Silver" Height="390px" OnInitializePostBack="WebGrid1_InitializePostBack" OnInitializeRow="WebGrid1_InitializeRow" OnInitializeDataSource="WebGrid1_InitializeDataSource">
                <LayoutSettings AllowAddNew="No" EditOnClick="True" AllowColumnMove="No"
                    AllowEdit="No" AllowDelete="Yes" AllowSorting="Yes" ColumnFooters="Yes" NewRowLostFocusAction="AlwaysUpdate"
                    ResetNewRowValuesOnError="False" InProgressUIBehavior="ChangeCursorToHourGlass"
                    AlwaysShowHelpButton="false" PagingMode="ClassicPaging" PagingSize="12" ColumnFooterAggregateMode="CalculateAllData"
                    VirtualLoadMode="LargeData" AllowGrouping="Yes" VirtualPageSize="12">
                    <RowStyle Font-Names="Tahoma" Font-Size="9" CustomRules="overflow: hidden;" />
                    <AlternatingRowStyle Font-Names="Tahoma" Font-Size="9" BackColor="#fbfbfb" CustomRules="overflow: hidden;" />
                    <ClientSideEvents OnRowValidate="WebGrid1_OnRowValidate" OnRowContextMenu="WebGrid1_OnRowContextMenu" OnEditKeyDown="WebGrid1_OnEditKeyDown" />
                </LayoutSettings>
                <RootTable DataKeyField="id" >
                    <Columns>
                        <ISWebGrid:WebGridColumn Caption="Plan Year" DataMember="PlanYear" DataType="System.Int16" Name="PlanYear" Width="100" TextboxMaxlength="4">
                            <HeaderStyle HorizontalAlign="Center" />
                            <CellStyle HorizontalAlign="Center" />
                        </ISWebGrid:WebGridColumn>
                        <ISWebGrid:WebGridColumn Caption="FundCenter" DataMember="FundCenter" Name="FundCenter" Width="20%">
                            <HeaderStyle HorizontalAlign="Center" />
                        </ISWebGrid:WebGridColumn>
                        <ISWebGrid:WebGridColumn Caption="CommitmentItem" DataMember="CommitmentItem" Name="CommitmentItem" Width="20%">
                            <HeaderStyle HorizontalAlign="Center" />
                        </ISWebGrid:WebGridColumn>
                        <ISWebGrid:WebGridColumn Caption="FundedProgram" DataMember="FundedProgram" Name="FundedProgram" Width="20%">
                            <HeaderStyle HorizontalAlign="Center" />
                        </ISWebGrid:WebGridColumn>
                        <ISWebGrid:WebGridColumn Caption="Strategy" DataMember="Strategy" Name="Strategy" Width="20%">
                            <HeaderStyle HorizontalAlign="Center" />
                        </ISWebGrid:WebGridColumn>
                        <ISWebGrid:WebGridColumn Caption=" " ColumnType="Template" Name="Attachment" Width="5%">
                            <CellTemplate>
                                <a href="#" style="text-decoration: none; border: none;">
                                    <img src="Icons/document_edit.png" height="16" id='Img1' style="text-decoration: none; border: none;" title="แก้ไข" 
                                        onclick="popupkrajay3('2','<%# Eval("Id")%>','<%# Eval("PlanYear")%>','<%# Eval("FundCenter")%>','<%# Eval("CommitmentItem")%>','<%# Eval("FundedProgram")%>');" />
                                </a>
                                <a href="#" style="text-decoration: none; border: none;">
                                    <img src="Icons/ic_deleteRed.png" height="16px"   style="text-decoration: none; border: none;" title="ลบ" onclick="CustomRequestDel('<%# Eval("Id")%>');" />
                                </a>
                            </CellTemplate>
                            <CellStyle HorizontalAlign="Center"></CellStyle>
                        </ISWebGrid:WebGridColumn>


                    </Columns>
                </RootTable>
            </ISWebGrid:WebGrid>
        </div>
    </div>
    <br />
    <br />
    <br />
    <%= ScripText %>
</asp:Content>